/*
 * @Author: 姚潘涛
 * @Date: 2024-06-03 10:40:39
 * @LastEditors: 姚潘涛
 * @LastEditTime: 2024-10-10 18:43:47
 * @Description:
 *
 * Copyright (c) 2024 by pandaman, All Rights Reserved.
 */
#pragma once

#include "macros.h"
#include "xict_common/perception/common/cuda_utils.h"
#include "xict_common/perception/common/utils.h"
#include <fstream>
#include <iostream>
#include <iterator>
#include <opencv2/dnn/dnn.hpp>
#include <opencv2/opencv.hpp>
#include <string>
#include <vector>
namespace xict_common {
    namespace perception {
        namespace common {
            // ! \class Int8EntropyCalibrator2
            // !
            // ! \brief Implements Entropy calibrator 2.
            // !  CalibrationAlgoType is kENTROPY_CALIBRATION_2.
            // !
            class Int8EntropyCalibrator2
                : public nvinfer1::IInt8EntropyCalibrator2 {
            public:
                Int8EntropyCalibrator2(int batchsize, int input_w, int input_h,
                                       const char* img_dir,
                                       const char* calib_table_name,
                                       const char* input_blob_name,
                                       bool read_cache = true);

                virtual ~Int8EntropyCalibrator2();
                int getBatchSize() const TRT_NOEXCEPT override;
                bool getBatch(void* bindings[], const char* names[],
                              int nbBindings) TRT_NOEXCEPT override;
                const void*
                readCalibrationCache(size_t& length) TRT_NOEXCEPT override;
                void writeCalibrationCache(const void* cache,
                                           size_t length) TRT_NOEXCEPT override;

            private:
                int batchsize_;
                int input_w_;
                int input_h_;
                int img_idx_;
                std::string img_dir_;
                std::vector<std::string> img_files_;
                size_t input_count_;
                std::string calib_table_name_;
                const char* input_blob_name_;
                bool read_cache_;
                void* device_input_;
                std::vector<char> calib_cache_;
            };
        }   // namespace common
    }       // namespace perception
}   // namespace xict_common